<?php
$where=' 1=1 and status=1 ';
$sdate=$_POST["sdate"];
$q=trim($_POST['q']);
$type=$_POST['type'];
if($q<>""){
    
    $where.=" and (name like '%".$q."%' or description1 like '%".$q."%' or description3 like '%".$q."%') ";
}
if(!empty($type)){
   $where.= " and type=".$type."";
}
if(!empty($sdate)){
    
     $where.= " and  id in (select chefid  from ce_shopping3_schedule  where sdate>='$sdate')";  
}
$page=isset($_POST['page'])?$_POST['page']:1;
$pagesize=2;
$list = pdo_fetchall("SELECT * FROM ".tablename('shopping3_chef')."where ".$where." ORDER BY createtime DESC, id DESC LIMIT ".($page-1)*$pagesize.",".$pagesize."");
$total = pdo_fetchall("SELECT count(1) as total FROM ".tablename('shopping3_chef')."where ".$where."");
$count_all = $total[0]['total'];
$count=count($list)+($page-1)*$pagesize;
$pagecount=ceil($count_all/$pagesize);
$cuisinelist=array(
            '0'=>array('name'=>'请选择','img'=>''),
            '1'=>array('name'=>'鲁菜','img'=>'/images/bd01.png'),
            '2'=>array('name'=>'粤菜','img'=>'/images/bd03.png'),
            '3'=>array('name'=>'川菜','img'=>'/images/bd02.png'),
            '4'=>array('name'=>'湘菜','img'=>'/images/bd07.png'),
            '5'=>array('name'=>'闽菜','img'=>'/images/bd04.png'),
            '6'=>array('name'=>'浙菜','img'=>'/images/bd06.png'),
            '7'=>array('name'=>'苏菜','img'=>'/images/bd05.png'),
            '8'=>array('name'=>'徽菜','img'=>'/images/bd08.png'),
);
foreach($list as $key=>$val){
    if(array_key_exists($val['cuisine'],$cuisinelist)){
        $list[$key]['cuisine_img']="<img src='".$cuisinelist[$val['cuisine']]['img']."' width='30' />";
        $list[$key]['cuisine_name']=$cuisinelist[$val['cuisine']]['name'];
        $list[$key]['detaillink']=$this->createMobileUrl('wldetailnew',array('id'=>$val['id']));
    }
    $list[$key]['description3']=trim(strip_tags($list[$key]['description3']));
    $list[$key]['description3']=cutstr($list[$key]['description3'],32,1);
}
if($page<=$pagecount){
    $list['page']=$page+1;
    $list['count_all']=$count_all;
    $list['count']=$count;
    $list['pagesize']=$pagesize;
    $list['flag']=1;
}else{
   $list['flag']=0;  
}
echo json_encode($list);
?>
